home *** CD-ROM | disk | FTP | other *** search
- 1 ! plot-8300P
- 2 call set_constants
- 3 dim y(MAXSIZE), ylab$(MAXLABEL), xlab$(MAXLABEL)
- 4 print clr$;"plot-8300P - D. A. Staley, Thornhill": print
- 5 print "Requires MicroBASIC Version 1.0": print
- 6 print "Enter 1 for a LINEAR plot."
- 7 print " 2 for a LOG-LINEAR plot."
- 8 print " 3 for a LOG-LOG plot." : print
- 9 call get_params
- 10 call get_data
- 11 call scale_data
- 12 call draw_border
- 13 call annotate_yaxis
- 14 call get_labels
- 15 call annotate_xaxis
- 16 call plot_graph
- 17 call print_labels
- 18 ! stop
- 19
- 20 proc set_constants
- 21 LAST = 2 : MAXSIZE = 600 : MAXLABEL = 25
- 22 spi = 120: cpi = 10 : lpi = 6 : hlpi = 12
- 23 spl = 8 : vsi = 48 : dh = 0
- 24 bs$ = chr$(8) : lf$ = chr$(10) : up$ = chr$(11)
- 25 clr$= chr$(12): rtn$= chr$(13) : esc$= chr$(27)
- 26 sp$ = chr$(32): pd$ = chr$(46) : us$ = chr$(95)
- 27 vl$ = chr$(124) : bl$ = rpt$(sp$,78)
- 28 HMI$= esc$ + chr$(31) : VMI$ = esc$ + chr$(30)
- 29 hlf$= esc$ + chr$(85) : nhlf$= esc$ + chr$(68)
- 30 nlf$= esc$ + chr$(10) : ebp$ = esc$ + chr$(54)
- 31 dbp$= esc$ + chr$(53) : gon$ = esc$ + chr$(51)
- 32 gof$= esc$ + chr$(52)
- 33 endproc
- 34
- 35 proc get_params
- 36 type% = fnparam(" Type of plot ",1,3)
- 37 h = fnparam("Plot height (inches) ",0,11)
- 38 paper = fnparam(" Paper width ",0,14)
- 39 marg = fnparam(" Left margin ",0,paper-1)
- 40 wide = fnparam(" Plot width ",0,paper-marg-0.5)
- 41 endproc
- 42
- 43 def fnparam(prompt$,low,hi)
- 44 loop
- 45 print prompt$;: input num$
- 46 test$ = fnnumeric$(num$)
- 47 if test$ = "yes" then numb = value(num$)
- 48 if test$ <> "yes" then numb = low-1
- 49 if ( numb >= low and numb <= hi ) then quit
- 50 print up$;bl$;rtn$;up$;
- 51 endloop
- 52 fnparam = numb
- 53 fnend
- 54
- 55 def fnnumeric$(num$)
- 56 fnnumeric$ = "yes"
- 57 if len(num$) = 0 then fnnumeric$ = "no"
- 58 for i = 1 to len(num$)
- 59 a = ord(num$(i:i))
- 60 if a < 46 or a > 57 or a = 47 then fnnumeric$="no"
- 61 next i
- 62 fnend
- 63
- 64 proc get_data
- 65 on eof ignore : on ioerr ignore
- 66 on conv
- 67 call error("Not a plot file.")
- 68 endon
- 69 loop
- 70 input " Data file name ? ",nm$
- 71 open #8, "disk/0."+ nm$, input
- 72 if io_status = 0 then quit
- 73 print up$;bl$;rtn$;up$;
- 74 endloop
- 75 input #8, origin, delta
- 76 if io_status <> 0 then call error(io_status$)
- 77 if origin <= 0 and type% = 3 then call error("Origin out of range")
- 78 if delta <= 0 then call error("Descending time axis?")
- 79 n=0
- 80 while io_status <> LAST
- 81 n = n + 1 : input #8, y(n)
- 82 if io_status = 1 or io_status = 3 then call error(io_status$)
- 83 endloop
- 84 n = n - 1 : close #8
- 85 print " sample origin = ";origin
- 86 print " sample interval = ";delta
- 87 print "Number of points = ";n
- 88 if type% <> 3 and 2*n/spi > wide
- 89 n = int(spi*wide/2)
- 90 print "The first "+value$(n)+" points will fit plot width."
- 91 elseif type% <> 3
- 92 wide = 2*n/spi
- 93 endif
- 94 endproc
- 95
- 96 proc error(msg$)
- 97 print msg$: close #8
- 98 stop
- 99 endproc
- 100
- 101 proc scale_data
- 102 max = y(1) : min = y(1)
- 103 for i = 1 to n
- 104 if y(i) > max then max = y(i)
- 105 if y(i) < min then min = y(i)
- 106 next i
- 107 if min <= 0 and type% > 1 then call error("Data out of range")
- 108 if type% > 1
- 109 maxex = int(log(max)/log(10)) : minex = int(log(min)/log(10))
- 110 maxlog = -10^maxex*int(-abs(max)/10^maxex)*sgn(max)
- 111 minlog = 10^minex*int(min/10^minex)
- 112 t = vsi/(log(maxlog/minlog)) : ysp = 8 : scale = h*t
- 113 for i = 1 to n
- 114 y(i) = scale*(log(y(i)/min))
- 115 next i
- 116 else
- 117 pow = log(max-min)/log(10) : ex = int(pow)
- 118 if pow = ex then ex = ex - 1
- 119 min = 10^ex * int( min/10^ex )
- 120 max = -10^ex * int(-abs(max)/10^ex ) * sgn(max)
- 121 maxl = max/10^ex : minl = min/10^ex : t = vsi/(max-min)
- 122 ysp = -int(-h*t*10^ex): h = (1+ysp)/(t*10^ex) : scale = h*t
- 123 for i = 1 to n
- 124 y(i) = scale*(y(i)-min)
- 125 next i
- 126 endif
- 127 endproc
- 128
- 129 proc draw_border
- 130 open #4,"ieee4",output
- 131 print #4,nm$;rtn$;lf$;lf$;HMI$;chr$(13);
- 132 print #4,rpt$(sp$,cpi*marg);rpt$(us$,cpi*wide);
- 133 print #4,HMI$;chr$(7);bs$;HMI$;chr$(1);
- 134 print #4,VMI$;chr$(9);hlf$;rpt$(hlf$+vl$,h*hlpi);
- 135 print #4,VMI$;chr$(4);nlf$;VMI$;chr$(9);
- 136 print #4,HMI$;chr$(7);bs$;HMI$;chr$(13);
- 137 print #4,ebp$;rpt$(us$,cpi*wide);dbp$;
- 138 print #4,HMI$;chr$(7);sp$;HMI$;chr$(1);
- 139 print #4,VMI$;chr$(3);lf$;VMI$;chr$(9);
- 140 print #4,rpt$(vl$+nhlf$,h*hlpi);
- 141 print #4,HMI$;chr$(13);sp$;
- 142 endproc
- 143
- 144 proc annotate_yaxis
- 145 print #4,VMI$;chr$(9);nlf$;
- 146 expon$ = value$(minex)
- 147 if type% = 1 then expon$ = value$(ex)
- 148 print #4,rpt$(bs$,len(expon$)+3);"x10";nhlf$;expon$;
- 149 print #4,hlf$;VMI$;chr$(11);lf$;VMI$;chr$(ysp+1);nlf$;
- 150 if type% > 1
- 151 nu = maxlog/10^maxex : tens = maxex - minex
- 152 cy = -int(-tens) : b$ = value$(nu*10^tens) + " -"
- 153 d = 0 : st = 0 : l$ = "no"
- 154 loop
- 155 a$ = value$(nu*10^tens) + " -"
- 156 if (str$(a$,1,1) <> "-") then a$ = " " + a$
- 157 print #4,rpt$(bs$,len(a$));lf$;a$;
- 158 call get_newnu
- 159 if newnu*10^tens < minlog/10^minex
- 160 if l$ = "yes" then quit
- 161 l$ = "yes" : newnu = minlog/10^minex/10^tens
- 162 endif
- 163 d = d + scale*log(nu/newnu)
- 164 ys = int(d-st) : st = st + ys : nu = newnu
- 165 print #4,VMI$;chr$(ys+1);
- 166 if nu = 1
- 167 tens = tens - 1 : nu = 10
- 168 endif
- 169 if nu*10^tens < minlog/10^minex then quit
- 170 endloop
- 171 if str$(b$,1,1) <> "-" then a$ = " " + b$
- 172 else
- 173 dh = -vsi*int(-h*hlpi)/hlpi - (maxl-minl)*ysp
- 174 if dh >= 0 then print #4,VMI$;chr$(dh+1);lf$;VMI$;chr$(ysp+1);
- 175 if dh < 0 then print #4,VMI$;chr$(1-dh);nlf$;VMI$;chr$(ysp+1);
- 176 for i = maxl to minl step -1
- 177 a$ = value$(i) + " -"
- 178 if str$(a$,1,1) <> "-" then a$ = " " + a$
- 179 print #4,rpt$(bs$,len(a$));lf$;a$;
- 180 next i
- 181 endif
- 182 print #4,bs$;
- 183 endproc
- 184
- 185 proc get_newnu
- 186 if cy = 1
- 187 newnu = nu - 1
- 188 if nu = 1
- 189 nu = 10 : newnu = 9 : tens = tens - 1
- 190 endif
- 191 elseif cy = 2
- 192 newnu = nu - 2
- 193 if nu - 2*int(nu/2) > 0 then newnu = nu -1
- 194 if nu = 2
- 195 nu = 20 : newnu = 10 : tens = tens -1
- 196 endif
- 197 elseif cy >= 3
- 198 if nu > 5 then newnu = 5
- 199 if nu <= 5 and nu > 2 then newnu = 2
- 200 if nu = 2 then newnu = 1
- 201 endif
- 202 endproc
- 203
- 204 proc get_labels
- 205 w = cpi*marg - len(a$) : s$ = rpt$("x",w) : nl% = lpi*h
- 206 print : print "Y-axis label. << to change, +++ to end."
- 207 print : print " ";s$
- 208 loop
- 209 for i% = 1 to nl%
- 210 i1% = i% : yln% = -1 : linput ylab$(i%) : again$ = "no"
- 211 if idx(ylab$(i%),"+++") <> 0 then yln% = i% - 1
- 212 if yln% > -1 then quit
- 213 if idx(ylab$(i%),"<<") <> 0 then again$ = "yes"
- 214 if again$ = "yes" then quit
- 215 next i%
- 216 if again$ = "no" then quit
- 217 print rpt$(up$,i1%);
- 218 endloop
- 219 w = cpi*wide : s$ = rpt$("x",w)
- 220 print : print "X-axis label, << to change, +++ to end."
- 221 print : print " ";s$
- 222 loop
- 223 for i% = 1 to MAXLABEL
- 224 i1% = i% : xln% = -1 : linput xlab$(i%)
- 225 if idx(xlab$(i%),"+++") <> 0 then xln% = i% - 1
- 226 again$ = "no"
- 227 if xln% > -1 then quit
- 228 if idx(xlab$(i%),"<<") <> 0 then again$ = "yes"
- 229 if again$ = "yes" then quit
- 230 next i%
- 231 if again$ = "no" then quit
- 232 print rpt$(up$,i1%);
- 233 endloop
- 234 endproc
- 235
- 236 proc annotate_xaxis
- 237 if type% = 3 then call logarithmic_xaxis_annotation
- 238 if type% <> 3 then call linear_xaxis_annotation
- 239 endproc
- 240
- 241 proc logarithmic_xaxis_annotation
- 242 print #4,VMI$;chr$(11);
- 243 xs = wide*spi/log(n) : minex = int(log(origin)/log(10))
- 244 tens = 0 : cy = -int(-log(n)/log(10))
- 245 nu = int(origin/10^minex) : call get_newnux : fx = 0
- 246 if nu*10^minex < origin
- 247 fx = xs*log(newnu*10^minex/origin) : nu = newnu
- 248 endif
- 249 if nu = 10
- 250 nu = 1 : minex = minex + 1
- 251 endif
- 252 x = int(fx) : d = fx : st = x
- 253 while st <= wide*spi
- 254 a$ = value$(nu*10^tens) : call print_numbers
- 255 call get_newnux : d = d + xs*log(newnu/nu)
- 256 x = int(d-st) : st = st + x : nu = newnu
- 257 if nu = 10
- 258 tens = tens + 1 : nu = 1
- 259 endif
- 260 endloop
- 261 expon$ = value$(minex) : lx = wide*spi-st+x
- 262 sh = wide*spi : call show_power
- 263 endproc
- 264
- 265 proc get_newnux
- 266 if cy = 1
- 267 newnu = nu + 1
- 268 elseif cy = 2
- 269 newnu = nu + 2
- 270 if nu - 2*int(nu/2) > 0 then newnu = nu + 1
- 271 elseif cy >= 3
- 272 if nu >= 5 then newnu = 10
- 273 if nu < 5 and nu >= 2 then newnu = 5
- 274 if nu = 1 then newnu = 2
- 275 endif
- 276 endproc
- 277
- 278 proc print_numbers
- 279 call print_big_space
- 280 if x > 0 then print #4,HMI$;chr$(x+1);sp$;
- 281 print #4,HMI$;chr$(1);vl$;lf$;HMI$;chr$(9);
- 282 print #4,rpt$(bs$,int(len(a$)/2));a$;
- 283 print #4,rpt$(bs$,int((len(a$)+1)/2));nlf$;
- 284 endproc
- 285
- 286 proc print_big_space
- 287 while x >= 120
- 288 print #4,HMI$;chr$(121);sp$;
- 289 x = x - 120 : ste = ste + 120
- 290 endloop
- 291 endproc
- 292
- 293 proc linear_xaxis_annotation
- 294 pow = log(n*delta)/log(10) : ex = int(pow)
- 295 if pow = ex then ex = ex - 1
- 296 min1 = 10^ex*int(origin/10^ex) : min2 = min1/10^ex
- 297 print #4,VMI$;chr$(11);
- 298 xs = 2*10^ex/delta : adx = 1
- 299 if int( 2*n/xs ) < 3
- 300 xs = xs/2 : adx = 5 : ex = ex - 1
- 301 endif
- 302 k = min2 + adx : fx = xs - 2*(origin-min1)/delta
- 303 if origin = min1
- 304 fx = 0 : k = min2
- 305 endif
- 306 x = int(fx) : d = fx : st = x
- 307 while st <= 2*n
- 308 a$ = value$(k) : call print_numbers
- 309 k = k + adx : d = d + xs
- 310 x = int(d-st) : st = st + x
- 311 endloop
- 312 expon$ = value$(ex) : lx = 2*n-st+x
- 313 sh = 2*n : call show_power
- 314 endproc
- 315
- 316 proc show_power
- 317 st = st - x
- 318 if lx > 0
- 319 x = int(lx) : ste = st
- 320 call print_big_space : st = ste + x
- 321 print #4,HMI$;chr$(x+1);sp$;
- 322 endif
- 323 print #4,HMI$;chr$(13);lf$;sp$;sp$;
- 324 print #4,"x10";nhlf$;expon$;hlf$;
- 325 print #4,rpt$(bs$,len(expon$)+5);HMI$;chr$(13);
- 326 st = st-12*int(sh/12) : print #4,rpt$(bs$,int(sh/12));
- 327 if st > 0 then print #4,HMI$;chr$(st+1);bs$;HMI$;chr$(13);
- 328 print #4,VMI$;chr$(13);nlf$;VMI$;chr$(9);
- 329 endproc
- 330
- 331 proc plot_graph
- 332 told% = 0 : print #4,gon$;
- 333 if type% = 3
- 334 xs = wide*spi/(2*log(n))
- 335 st = 0 : nst = 0 : d = 0
- 336 endif
- 337 for i = 1 to n
- 338 t% = y(i) + 0.5*sgn(y(i))
- 339 r% = t% - told% : told% = t%
- 340 if r% < 0 then print #4,rpt$(lf$,-r%);pd$;
- 341 if r% = 0 then print #4,pd$;
- 342 if r% > 0 then print #4,rpt$(nlf$,r%);pd$;
- 343 if type% = 3
- 344 in = xs*log((i+1)/i) : d = d + in
- 345 nst = int(d-st) : st = st + nst
- 346 print #4,rpt$(sp$,nst);
- 347 else
- 348 print #4,sp$;
- 349 endif
- 350 next i
- 351 print #4,gof$;HMI$;chr$(13);VMI$;chr$(9)
- 352 endproc
- 353
- 354 proc print_labels
- 355 if type% = 1 then top% = 1 + (scale*(max-min)-y(n))/spl
- 356 if type% = 2 then top% = 1 + (scale*log(max/min)-y(n))/spl
- 357 if type% = 3 then top% = 1 + (scale*log(max/min)-y(n))/spl
- 358 mv% = top% - (nl%-yln%)/2
- 359 if mv% >= 0 then print #4, rpt$(nlf$,mv%);
- 360 if mv% < 0 then print #4, rpt$(lf$,-mv%)
- 361 for i% = 1 to yln%
- 362 print #4,ylab$(i%)
- 363 next i%
- 364 mv% = 4 + (nl%-yln%)/2
- 365 print #4,rpt$(lf$,mv%);
- 366 for i% = 1 to xln%
- 367 print #4,rpt$(sp$,cpi*marg);xlab$(i%)
- 368 next i%
- 369 close #4
- 370 endproc
-